package com.sxhuayuan.parking.queue.msg;

import java.io.Serializable;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 通知车场交费完成的消息体
 * 
 * @author gy
 */
@Setter
@Getter
@NoArgsConstructor
public class NotifyParkingLotMsg implements Serializable {

	private static final long serialVersionUID = 6242562312390931877L;
	// 最大通知失败次数
	private static final Integer MAX_FAIL_COUNT = 10;
	// 通知失败时重试计划，单位秒
	public static final Integer[] RETRY_PLAN = new Integer[] { 3, 3, 4, 4, 5, 5 };
	// 停车插件id
	private String pluginId;
	// 本系统订单号
	private String localOrderSn;
	// 本系统车场编号
	private String localLotSn;
	// 车场自己的编号
	private String outLotSn;
	// 车牌号
	private String carPlate;
	// 车场入场唯一编号
	private String outParkRecordId;
	// 出口系统编号
	private String localChannelSn;
	// 出口第3方车道编号
	private String channelSn;
	// 出口第3方设备编号
	private String deviceId;

	/** 通知失败次数，如果超过3次就取消推送 */
	private Integer notifyFailCount = 0;

	public NotifyParkingLotMsg(String pluginId, String localOrderSn, String localLotSn, String carPlate, String outParkRecordId) {
		this.pluginId = pluginId;
		this.localOrderSn = localOrderSn;
		this.localLotSn = localLotSn;
		this.carPlate = carPlate;
		this.outParkRecordId = outParkRecordId;
	}

	/**
	 * 通知失败
	 */
	public void notifyFail() {
		this.notifyFailCount++;
	}

	/**
	 * 是否超过最大通知次数，超过则从队列中移除
	 * 
	 * @return
	 */
	@JSONField(serialize = false)
	@JsonIgnore
	public boolean isNotifyTimeout() {
		return this.notifyFailCount >= MAX_FAIL_COUNT;
	}
}
